package com.auemall.controller;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.auemall.constant.ApplicationConstant;
import com.auemall.service.ItemBrandCheckedRespVO;
import com.auemall.service.ItemService;
import com.auemall.utils.EUDataGridResult;
import com.auemall.vo.BaseRespVO;
import com.auemall.vo.DeleteItemReqVO;
import com.auemall.vo.InsertItemSku;
import com.auemall.vo.ItemBrandVO;
import com.auemall.vo.ItemInfoVO;
import com.auemall.vo.ItemReqVO;
import com.auemall.vo.ItemSkuVO;


/**
 * 商品管理Controller
 * <p>Title: ItemController</p>
 * <p>Description: </p>
 *
 */

@Controller
public class ItemController {
    
    private Logger logger = Logger.getLogger(ItemController.class);

	@Autowired
	private ItemService itemService;
	
	/**
	 * 
	 * @Title: selectItemList 
	 * @Description: TODO(查询商品列表)
	 * @param page
	 * @param rows
	 * @return EUDataGridResult  
	 * @author WangChao
	 */
	@RequestMapping("/item/v1/list")
    @ResponseBody
    public EUDataGridResult selectItemList(@RequestBody ItemReqVO req,Integer page, Integer rows) {
	    EUDataGridResult result;
	    try{
	        result = itemService.selectItemList(req, page, rows);
	    }catch(Exception e){
	        result = new EUDataGridResult();
	        result.setResult(ApplicationConstant.RESULT_FALTURE);
	        result.setMsg("item/v1/list 查询商品列表失败："+e.getMessage());
	        logger.error(result.getMsg());
	    }
        return result;
    }
	
	/**
	 * 
	 * @Title: addItemInfo 
	 * @Description: TODO(添加商品信息)
	 * @param req
	 * @return BaseRespVO  
	 * @author WangChao
	 */
	@RequestMapping(value="/item/v1/additeminfo", method=RequestMethod.POST)
    @ResponseBody
    private BaseRespVO addItemInfo(ItemInfoVO req) {
        BaseRespVO respVO;
        try{
            respVO = itemService.addItemInfo(req);
        }catch(Exception e){
            respVO = new BaseRespVO();
            respVO.setResult(ApplicationConstant.RESULT_FALTURE);
            respVO.setMsg("添加商品信息异常（/item/v1/additeminfo）："+e.getMessage());
            logger.error(respVO.getMsg());
        }
        return respVO;
    }
	
	/**
	 * 
	 * @Title: updateItemInfo 
	 * @Description: TODO(修改商品信息)
	 * @param req
	 * @return BaseRespVO  
	 * @author WangChao
	 */
	@RequestMapping(value="/item/v1/updateiteminfo", method=RequestMethod.POST)
	@ResponseBody
	private BaseRespVO updateItemInfo(ItemInfoVO req) {
	    BaseRespVO respVO;
	    try{
	        respVO = itemService.updateItemInfo(req);
	    }catch(Exception e){
	        respVO = new BaseRespVO();
	        respVO.setResult(ApplicationConstant.RESULT_FALTURE);
	        respVO.setMsg("修改商品信息异常（/item/v1/updateiteminfo）："+e.getMessage());
	        logger.error(respVO.getMsg());
	    }
	    return respVO;
	}
	
	/**
	 * 
	 * @Title: deleteItemInfos 
	 * @Description: TODO(删除商品信息)
	 * @param req
	 * @return BaseRespVO  
	 * @author WangChao
	 */
	@RequestMapping("/item/v1/deleteiteminfos")
	@ResponseBody
	private BaseRespVO deleteItemInfos(@RequestBody DeleteItemReqVO req) {
	    BaseRespVO respVO;
	    try{
	        respVO = itemService.deleteItemInfos(req);
	    }catch(Exception e){
	        respVO = new BaseRespVO();
	        respVO.setResult(ApplicationConstant.RESULT_FALTURE);
	        respVO.setMsg("删除商品信息异常（/item/v1/deleteiteminfos）："+e.getMessage());
	        logger.error(respVO.getMsg());
	    }
	    return respVO;
	}
	
	/**
	 * 
	 * @Title: selectItemBrand 
	 * @Description: TODO(查询商品品牌列表)
	 * @param req
	 * @param page
	 * @param rows
	 * @return EUDataGridResult  
	 * @author WangChao
	 */
	@RequestMapping("/item/v1/selectitembrand")
    @ResponseBody
    public EUDataGridResult selectItemBrand(@RequestBody ItemBrandVO req,int page, int rows) {
        EUDataGridResult result;
        try{
            result = itemService.selectItemBrand(req, page, rows);
        }catch(Exception e){
            result = new EUDataGridResult();
            result.setResult(ApplicationConstant.RESULT_FALTURE);
            result.setMsg("item/v1/selectitembrand 查询商品品牌列表失败："+e.getMessage());
            logger.error(result.getMsg());
        }
        return result;
	}
	
	/**
	 * 
	 * @Title: selectItemBrandChecked 
	 * @Description: TODO(查询所有品牌【包括已选中品牌】)
	 * @param req
	 * @return ItemBrandCheckedRespVO  
	 * @author WangChao
	 */
	@RequestMapping("/item/v1/selectitembrandchecked")
    @ResponseBody
    public ItemBrandCheckedRespVO selectItemBrandChecked(@RequestBody ItemBrandVO req) {
	    ItemBrandCheckedRespVO result;
        try{
            result = itemService.selectItemBrandChecked(req);
        }catch(Exception e){
            result = new ItemBrandCheckedRespVO();
            result.setResult(ApplicationConstant.RESULT_FALTURE);
            result.setMsg("item/v1/selectitembrandchecked 查询所有品牌【包括已选中品牌】："+e.getMessage());
            logger.error(result.getMsg());
        }
        return result;
    }
	
	/**
	 * 
	 * @Title: addItemBrand 
	 * @Description: TODO(增加商品品牌)
	 * @param req
	 * @return BaseRespVO  
	 * @author WangChao
	 */
	@RequestMapping(value="/item/v1/additembrand", method=RequestMethod.POST)
    @ResponseBody
    private BaseRespVO addItemBrand(ItemBrandVO req) {
        BaseRespVO respVO;
        try{
            respVO = itemService.addItemBrand(req);
        }catch(Exception e){
            respVO = new BaseRespVO();
            respVO.setResult(ApplicationConstant.RESULT_FALTURE);
            respVO.setMsg("添加商品品牌异常（/item/v1/additembrand）："+e.getMessage());
            logger.error(respVO.getMsg());
        }
        return respVO;
    }
	
	/**
	 * 
	 * @Title: updateItemBrand 
	 * @Description: TODO(修改商品品牌)
	 * @param req
	 * @return BaseRespVO  
	 * @author WangChao
	 */
	@RequestMapping(value="/item/v1/updateitembrand", method=RequestMethod.POST)
	@ResponseBody
	private BaseRespVO updateItemBrand(ItemBrandVO req) {
	    BaseRespVO respVO;
	    try{
	        respVO = itemService.updateItemBrand(req);
	    }catch(Exception e){
	        respVO = new BaseRespVO();
	        respVO.setResult(ApplicationConstant.RESULT_FALTURE);
	        respVO.setMsg("修改商品品牌异常（/item/v1/updateitembrand）："+e.getMessage());
	        logger.error(respVO.getMsg());
	    }
	    return respVO;
	}
	
	/**
	 * 
	 * @Title: deleteItemBrand 
	 * @Description: TODO(删除商品品牌)
	 * @param req
	 * @return BaseRespVO  
	 * @author WangChao
	 */
	@RequestMapping("/item/v1/deleteitembrand")
	@ResponseBody
	private BaseRespVO deleteItemBrand(@RequestBody ItemBrandVO req) {
	    BaseRespVO respVO;
	    try{
	        respVO = itemService.deleteItemBrand(req);
	    }catch(Exception e){
	        respVO = new BaseRespVO();
	        respVO.setResult(ApplicationConstant.RESULT_FALTURE);
	        respVO.setMsg("删除商品品牌异常（/item/v1/deleteitembrand）："+e.getMessage());
	        logger.error(respVO.getMsg());
	    }
	    return respVO;
	}
	
	/**
	 * 
	 * @Title: insertItemSku 
	 * @Description: TODO(新增商品规格【商品发布时新增】)
	 * @param req
	 * @return InsertItemSku  
	 * @author WangChao
	 */
	@RequestMapping("/item/v1/insertitemsku")
    @ResponseBody
    private InsertItemSku insertItemSku(@RequestBody ItemSkuVO req) {
	    InsertItemSku respVO;
        try{
            respVO = itemService.insertItemSku(req);
        }catch(Exception e){
            respVO = new InsertItemSku();
            respVO.setResult(ApplicationConstant.RESULT_FALTURE);
            respVO.setMsg("新增商品规格异常（/item/v1/insertitemsku）："+e.getMessage());
            logger.error(respVO.getMsg());
        }
        return respVO;
    }
	
	/**
	 * 
	 * @Title: selectItemSku 
	 * @Description: TODO(查询商品规格)
	 * @param req
	 * @return EUDataGridResult  
	 * @author WangChao
	 */
	@RequestMapping("/item/v1/selectitemsku")
    @ResponseBody
    private EUDataGridResult selectItemSku(@RequestBody ItemSkuVO req) {
	    EUDataGridResult respVO;
        try{
            respVO = itemService.selectItemSku(req);
        }catch(Exception e){
            respVO = new EUDataGridResult();
            respVO.setResult(ApplicationConstant.RESULT_FALTURE);
            respVO.setMsg("查询商品规格异常（/item/v1/selectitemsku）："+e.getMessage());
            logger.error(respVO.getMsg());
        }
        return respVO;
    }
	
	/**
	 * 
	 * @Title: updateItemSku 
	 * @Description: TODO(修改商品规格)
	 * @param req
	 * @return BaseRespVO  
	 * @author WangChao
	 */
	@RequestMapping("/item/v1/updateitemsku")
    @ResponseBody
    private BaseRespVO updateItemSku(@RequestBody ItemSkuVO req) {
	    BaseRespVO respVO;
        try{
            respVO = itemService.updateItemSku(req);
        }catch(Exception e){
            respVO = new BaseRespVO();
            respVO.setResult(ApplicationConstant.RESULT_FALTURE);
            respVO.setMsg("修改商品规格异常（/item/v1/updateitemsku）："+e.getMessage());
            logger.error(respVO.getMsg());
        }
        return respVO;
    }
	
	/**
	 * 
	 * @Title: deleteItemSku 
	 * @Description: TODO(删除商品规格以及规格对应属性关联)
	 * @param req
	 * @return BaseRespVO  
	 * @author WangChao
	 */
	@RequestMapping("/item/v1/deleteitemsku")
    @ResponseBody
    private BaseRespVO deleteItemSku(@RequestBody ItemSkuVO req) {
        BaseRespVO respVO;
        try{
            respVO = itemService.deleteItemSku(req);
        }catch(Exception e){
            respVO = new BaseRespVO();
            respVO.setResult(ApplicationConstant.RESULT_FALTURE);
            respVO.setMsg("删除商品规格异常（/item/v1/deleteitemsku）："+e.getMessage());
            logger.error(respVO.getMsg());
        }
        return respVO;
    }
	
	
}
